﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using ePlanet.ArchiveMange.Services;
using ePlanet.ArchiveMange.Models;

namespace Web.Views.ArchiveBorrow.ArchiveBorrowView
{
    public partial class ArchiveBorrowCDKindView : ArchiveBorrowViewBase
    {
        [Dependency]
        public ICDArchiveService m_IDocumentArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }

        [Dependency]
        public Web.SystemConfig.Services.ICodeTable CodeTableService
        {
            get;
            set;
        }

        public string archiveTypeName;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["DataID"]))
                {
                    Guid dataID = new Guid(Request.QueryString["DataID"]);
                    this.InitArchiveBorrowModel(dataID);
                    if (this.m_CurrentArchiveBorrowModel != null)
                    {
                        ArchiveBorrowView masterPage = (ArchiveBorrowView)this.Master;
                        masterPage.CurrentArchiveBorrow = this.m_CurrentArchiveBorrowModel;
                        ArchiveMangeModal.CD_ARCHIVERow currentArchiveData = this.GetDocumentArchive(this.m_CurrentArchiveBorrowModel.ARCHIVEDATAID);
                        this.BindData(currentArchiveData);
                        //SetControlAttribute();
                    }
                }
                else
                {
                    Alert("参数DataID不能为空！");
                }
            }
        }

        #region 私有方法
        private void BindData(ArchiveMangeModal.CD_ARCHIVERow currentArchiveData)
        {
            ///绑定数据
            ///this.BindArchiveBorrowModel();
            this.BindDocumentArchive(currentArchiveData);
        }

        /// <summary>
        /// 绑定页面控件数据
        /// </summary>
        /// <param name="currentArchiveData"></param>
        private void BindDocumentArchive(ArchiveMangeModal.CD_ARCHIVERow row)
        {
            //throw new NotImplementedException();
            this.txtArchiveNum.Text = row.ARCHIVENUM;
            this.txtArchiveSource.Text = row.ARCHIVESOURCE;
            ArchiveMangeModal.ARCHIVEMENUDataTable dtMenu = ArchiveMenuService.GetArchiveMenuById(row.ARCHIVETYPE.ToString());
            ArchiveMangeModal.ARCHIVEMENURow drMenu = dtMenu.Rows[0] as ArchiveMangeModal.ARCHIVEMENURow;
            this.txtArchiveType.Text = drMenu.ARCHIVEMENU;
            this.archiveTypeName = drMenu.ARCHIVEMENU;
            this.h_ArchiveTypeId.Value = row.ARCHIVETYPE.ToString();

            this.txtBoxNum.Text = row.BOXNUM;
            //this.txtGloryType.Text = row.GLORYTYPE;
            //this.txtDoplicateBodyNum.Text = row.DOPLICATEBODYNUM.ToString();
            //this.txtFileNum.Text = row.FILENUM;
            //DataTable dtOrg = orgService.GetORGInfo(row.FILEORGID);
            //this.txtFileOrgName.Text = dtOrg.Rows[0]["Org_Name"].ToString();
            //this.h_FileOrgID.Value = row.FILEORGID;
            this.txtFileOrgName.Text = row.FILEORGID;
            this.txtFullFondsNum.Text = row.FULLFONDSNUM;
            this.txtMainBodyNum.Text = row.MAINBODYNUM.ToString();
            //this.txtPageNum.Text = row.PAGENUM.ToString();
            this.txtPublisher.Text = row.PUBLISHER;
            this.txtPublishTime.Text = row.PUBLISHTIME.ToString("yyyy-MM-dd");
            this.txtRemark.Text = row.REMARK;
            this.txtStorageType.Text = row.IsSTORAGETYPENull() ? string.Empty : row.STORAGETYPE;
            this.txtSummary.Text = row.SUMMARY;
            this.txtTempOrderNum.Text = row.TEMPORDERNUM;
            this.txtTitle.Text = row.TITLE;
            this.ddlCarrierType.Text = CodeTableService.GetpkNameByCodepkValue(row.F_CARRIERTYPE);
            this.ddlKeepTime.Text = CodeTableService.GetpkNameByCodepkValue(row.F_KEEPTIME);
            this.ddlSecurity.Text = CodeTableService.GetpkNameByCodepkValue(row.F_SECURITYTYPE);
            this.txtHujianhao.Text = row.HUJIANHAO;
            this.ddlKeepSecurityTime.Text = CodeTableService.GetpkNameByCodepkValue(row.F_KEEPSECURITYTIME);
        }

        /// <summary>
        /// 设置页面控件属性
        /// </summary>
        private void SetControlAttribute()
        {

        }

        private ArchiveMangeModal.CD_ARCHIVERow GetDocumentArchive(string dataID)
        {
            ArchiveMangeModal.CD_ARCHIVEDataTable oDataTable = this.m_IDocumentArchiveService.GetAllDocumenArchivetDataById(dataID);
            if (oDataTable != null && oDataTable.Rows.Count > 0)
            {
                return oDataTable.Rows[0] as ArchiveMangeModal.CD_ARCHIVERow;
            }
            else
            {
                return null;
            }
        }
        #endregion
    }
}